﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using FlyHorse.LIMS.Model;

namespace FlyHorse.LIMS.WinApp.XtraReportTemplate
{
    public partial class XtraReportMixOne : DevExpress.XtraReports.UI.XtraReport
    {
        OJCB4Entities db = new OJCB4Entities();
        public XtraReportMixOne(string reportID)
        {
            InitializeComponent();
            InitReport(reportID);
        }


        private void InitReport(string ID)
        {
            ReportMix report = db.ReportMixes.Find(ID);

            if (report.SamplingPlaceMixID=="3")    //包装
            {
                xrLabel_title.Text = "包装入库炭黑检验报告";
                xrTableCell9.Text = "批号";
                xrTableCell5.Text = "生产日期";
                xrTableCell20.Text = "包装数量";

                xrTableCell2.Text = "包装规格";
                xrTableCell13.Text = "包装袋数（袋)";
                xrTableCell14.Text = "送样人";
                xrTableCell22.Text = "检验日期";

                xrTableCell_GoodsName.Text = report.Good.GoodsName;
                xrTableCell_lotNO_SampleNO.Text = report.LotNO;
                if (report.ProduceDate!=null)
                {
                    xrTableCell_ProduceDate_Factory.Text = Convert.ToDateTime( report.ProduceDate).ToShortDateString();
                }
                xrTableCell_BagQuantiy_sampleQuantity.Text = report.PackingQuantity;

                xrTableCell_pageSpc_SendPerson.Text = report.packingSpecification;
                xrTableCell_packQuantity_SendDate.Text = report.BagQuantity;
                xrTableCell_SendPeron_Enviriment.Text = report.SampleSendPerson;
                if ( report.TestDate!=null)
                {
                    xrTableCell_TestDate.Text = Convert.ToDateTime( report.TestDate).ToShortDateString();
                }
                
            }
            else if (report.SamplingPlaceMixID == "16")   //外来
            {
                xrLabel_title.Text = "外来样品检验报告";
                xrTableCell9.Text = "样品编号";
                xrTableCell5.Text = "产品单位";
                xrTableCell20.Text = "样品数量";

                xrTableCell2.Text = "送样人";
                xrTableCell13.Text = "送样日期";
                xrTableCell14.Text = "温度℃/湿度%";
                xrTableCell22.Text = "检验日期";

                xrTableCell_GoodsName.Text = report.Good.GoodsName;
                xrTableCell_lotNO_SampleNO.Text = report.SampleNO;
                xrTableCell_ProduceDate_Factory.Text = report.Factory;
                xrTableCell_BagQuantiy_sampleQuantity.Text = report.SampleQuantity;

                xrTableCell_pageSpc_SendPerson.Text = report.SampleSendPerson;
                if (report.SendDate!=null)
                {
                    xrTableCell_packQuantity_SendDate.Text = Convert.ToDateTime( report.SendDate).ToShortDateString();
                }
                xrTableCell_SendPeron_Enviriment.Text = report.Environment;
                if (report.TestDate != null)
                {
                    xrTableCell_TestDate.Text = Convert.ToDateTime(report.TestDate).ToShortDateString();
                }
                
            }
            else
            {
                xrLabel_title.Text =report.Good.GoodsName+"-"+report.SamplingPlaceMix.SamplingPlaceName+ "检验报告";

                xrTableCell9.Text = "报告编号";
                xrTableCell5.Text = "样品属性";
                xrTableCell20.Text = "样品数量";

                xrTableCell2.Text = "送样人";
                xrTableCell13.Text = "综合判级";
                xrTableCell14.Text = "温度℃/湿度%";
                xrTableCell22.Text = "检验日期";

                xrTableCell_GoodsName.Text = report.Good.GoodsName;
                xrTableCell_lotNO_SampleNO.Text = report.ReportNO;
                xrTableCell_ProduceDate_Factory.Text = report.SamplingPlaceMix.SamplingPlaceName;
                xrTableCell_BagQuantiy_sampleQuantity.Text = "";

                xrTableCell_pageSpc_SendPerson.Text = report.SampleSendPerson;
                xrTableCell_packQuantity_SendDate.Text = report.Conclusion;
                xrTableCell_SendPeron_Enviriment.Text = report.Environment;
                if (report.TestDate != null)
                {
                    xrTableCell_TestDate.Text = Convert.ToDateTime(report.TestDate).ToShortDateString();
                }
            }

            //报告编号
            if (!String.IsNullOrEmpty(report.ReportNO))
            {
                xrTableCell_ReportNO.Text = report.ReportNO;
            }
            else
            {
                xrTable_reportNO.Visible = false;
            }
            xrTableCell_GoodsName.Text = report.Good.GoodsName;
            xrTableCell_conclution.Text = report.Conclusion;

         

            this.DataSource = report.ReportMixResults;

            xrTableCell_TestItemName.DataBindings.Add("Text", null, "ChineseName");
            xrTableCell_Basis.DataBindings.Add("Text", null, "Basis");
            xrTableCell_Unit.DataBindings.Add("Text", null, "Unit");
            xrTableCell_MinValue.DataBindings.Add("Text", null, "MinValue");
            xrTableCell_MaxValue.DataBindings.Add("Text", null, "MaxValue");
            xrTableCell_TestValue.DataBindings.Add("Text", null, "TestValue");
            xrTableCell_Conclusion.DataBindings.Add("Text", null, "Conclusion");


        }

    }
}
